<meta charset="UTF-8">

<script type="text/javascript">
	$(function(){
		$("#dept_user").treegrid({
			idField: 'id',
			treeField: 'name',
			title: '学院班级列表',
			fitColumns: true,
			singleSelect: true,
			collapsible: true,
			animate: true,
			striped: true,
			url: 'dept/list',
			columns:[
				[
					{field:'id',title:'ID',width: 20},
				 	{field:'name',title:'学院班级名称',width:200},
				 	{
				 		field: 'teacher',
						title: '负责人',
						width: 160,
						formatter: function(value, rec){ 
							return rec.teacher.name;
						}
				 	}
				]
			],
			dialog:{
				create:{
					action: 'dept/save'
				},
				update:{
					title: '修改',
					width: 430,
					height: 280,
					action: 'dept/save',
					href : 'dept/edit'
				},
				delete:{
					url: 'dept/delete'
				},
				reset:{
					url: 'dept/reset'
				}
			},
			toolbar:[{
				text: '新增',
				iconCls: 'icon-add',
				handler: function(){
					var $grid = $("#dept_user");
					//返回选中节点
					var row = $grid.treegrid('getSelected');
					//判断是否为空，为空返回null，不为空返回id
					var query = row?{parentId: row.id}:{};
					//创建一个div层
					var dialog = $('<div/>');
					//打开
					dialog.appendTo($grid.parent());
					//返回树形表格的属性
					var dlg = $grid.treegrid('options').dialog;
					var param = $.extend({
						title: '新增',
						width: 430,
						height: 280,
						href: 'dept/edit',
						modal: true,
						grid: $grid,
						queryParams: query,
						onClose: function(){
							dialog.dialog('destroy');
						},
						buttons:[$.dialog.buttons.save,$.dialog.buttons.reset,$.dialog.buttons.close]
					},dlg && dlg.create?dlg.create:{});
					dialog.dialog(param);
				}
			},'-',$.crudgrid.buttons.update,'-',$.crudgrid.buttons.delete,'-',$.crudgrid.buttons.reload,'-']
		});
	});
</script>

<table id = "dept_user"></table>

